<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="族名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入族名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分类id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="categoryid">
              <a-input v-model="model.categoryid" placeholder="请输入分类id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分类名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="categorynames">
              <a-input v-model="model.categorynames" placeholder="请输入分类名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="平台" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="platforms">
              <a-input v-model="model.platforms" placeholder="请输入平台"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopid">
              <a-input v-model="model.shopid" placeholder="请输入商品id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopname">
              <a-input v-model="model.shopname" placeholder="请输入商品名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="参数尺寸" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="parametricsize">
              <a-input v-model="model.parametricsize" placeholder="请输入参数尺寸"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否登记" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isregistered">
              <a-input v-model="model.isregistered" placeholder="请输入是否登记"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关键字" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="keywords">
              <a-input v-model="model.keywords" placeholder="请输入关键字"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="logourl" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logourl">
              <a-input v-model="model.logourl" placeholder="请输入logourl"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品牌名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brandname">
              <a-input v-model="model.brandname" placeholder="请输入品牌名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品牌code" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brandcode">
              <a-input v-model="model.brandcode" placeholder="请输入品牌code"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下载次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="downloadcount">
              <a-input v-model="model.downloadcount" placeholder="请输入下载次数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="喜爱次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="favoritecount">
              <a-input v-model="model.favoritecount" placeholder="请输入喜爱次数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="pageView" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pageview">
              <a-input v-model="model.pageview" placeholder="请输入pageView"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="createTime" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createtime">
              <j-date placeholder="请选择createTime" v-model="model.createtime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="thumbnail" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thumbnail">
              <a-input v-model="model.thumbnail" placeholder="请输入thumbnail"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="isFavourite" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isfavourite">
              <a-input v-model="model.isfavourite" placeholder="请输入isFavourite"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="hasBuiltinPlaceholde" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hasbuiltinplaceholder">
              <a-input v-model="model.hasbuiltinplaceholder" placeholder="请输入hasBuiltinPlaceholde"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="fileSize" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="filesize">
              <a-input-number v-model="model.filesize" placeholder="请输入fileSize" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'FamilyForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/fammanager/family/add",
          edit: "/fammanager/family/edit",
          queryById: "/fammanager/family/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>